package com.etc.zmall.dao.impl;

import java.util.List;

import com.etc.util.DBUtil;
import com.etc.util.PageData;
import com.etc.zmall.dao.GoodsTypeDao;
import com.etc.zmall.entity.GoodsType;

/**
 * GoodsTypeDao实现类
 * 
 * @author knowno
 *
 */
public class GoodsTypeDaoImpl implements GoodsTypeDao {

	@Override
	public List<GoodsType> selGoodsType() {
		String sql = "select typename from tbl_goodstype";
		List<GoodsType> list = (List<GoodsType>) DBUtil.exQuery(sql, GoodsType.class, null);
		return list;
	}

	@Override
	public boolean addGoodsType(GoodsType gt) {
		String sql = "insert into tbl_goodstype values(null,?,?)";
		return DBUtil.exUpdate(sql, gt.getTypename(), gt.getTypeinfo());
	}

	@Override
	public boolean molGoodsType(int typeid, String typename, String typeinfo) {
		String sql = "update tbl_goodstype set typename =?,typeinfo=? where typeid=?";
		return DBUtil.exUpdate(sql, typename, typeinfo, typeid);
	}

	@Override
	public boolean delGoodsType(String typename) {
		String sql = "delete from tbl_goodstype where typename=?";
		return DBUtil.exUpdate(sql, typename);
	}

	@Override
	public List<GoodsType> selGoodsTypeAll() {
		String sql = "select typeid,typename,typeinfo from tbl_goodstype";
		List<GoodsType> list = (List<GoodsType>) DBUtil.exQuery(sql, GoodsType.class, null);
		return list;
	}
	
	@Override
	public PageData<GoodsType> queryTypeByPage(int page, int pageSize, String keywords) {
		String sql = "select * from tbl_goodstype where typename like ? ";
		return DBUtil.exQueryByPage(sql,GoodsType.class,page,pageSize,"%"+keywords+"%");
	}

}
